package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.UserLoginDTO;
import net.wanho.service.LoginService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class LoginController {
    private final LoginService loginService;

    /**
     * 获取验证码
     */
    @GetMapping("/captchaImage")
    public AjaxResult captchaImage() {
        return AjaxResult.success(loginService.createCaptchaVo());
    }

    /**
     * 带验证码登录
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginDTO userLoginDTO) {
        return AjaxResult.success(loginService.captchaLogin(userLoginDTO));
    }

    /**
     * 获取当前用户信息
     */
    @GetMapping("/curr-user")
    public AjaxResult currUser() {
        return AjaxResult.success(loginService.getCurrUser());
    }

    /**
     * 退出登录
     */
    @DeleteMapping("/logout")
    public AjaxResult logout() {
        loginService.logout();
        return AjaxResult.success();
    }
}
